import {
  LOGIN,
  ROUTES,
  starLinkLogin,
  starLinkError,
  lineAlarm,
  deviceAlarm,
  starLinkErrorNum,
  starLinkErrorTypes,
  allStar,
  userInfo,
  upgradeTask,
  starlinkUpgradeStatus,
  starlinkList,
  historyStatus,
  deleteLink,
  alarmClass,
  downloadHistory,
  upgradeDizuo,
  upgradeSignal,
  upgradeDasuanli,
  addLink,
  addLinks,
  starlinkAllStatus,
  lightControl,
  powerControl,
  starlinkScene,
  upgradeAi
} from '@/services/api'
import {request, METHOD, removeAuthorization} from '@/utils/request'

/**
 * 登录服务
 * @param name 账户名
 * @param password 账户密码
 * @returns {Promise<AxiosResponse<T>>}
 */
export async function login(name, password) {
  return request(LOGIN, METHOD.POST, {
    name: name,
    password: password
  })
}

// 批量删除星链设备
export async function postDeleteStarlink(starlinkIds,operator) {
  return request(deleteLink, METHOD.POST, {
    requestId:new Date().getTime(),
    data: [{
      starlinkIds: starlinkIds,
      operator:operator
    }]
  })
}

// 升级底座
export async function postUpgradeDizuo(data) {
  return request(upgradeDizuo, METHOD.POST, data)
}
// 升级感知
export async function postUpgradeAi(data) {
  return request(upgradeAi, METHOD.POST, data)
}

// 信号
export async function postUpgradeSignal(data) {
  return request(upgradeSignal, METHOD.POST, data)
}
// 升级大算力
export async function postUpgradeDasuanli(data) {
  return request(upgradeDasuanli, METHOD.POST, data)
}


// addLink
export async function postAddLink(data) {
  return request(addLink, METHOD.POST, data)
}

export async function postAddLinks(data) {
  return request(addLinks, METHOD.POST, data)
}

export async function starLogin(name, password) {
  return request(starLinkLogin, METHOD.POST, {
    requestId:new Date().getTime(),
    data: [{
      username: name,
      password: password
    }]
  })
}
//获取星链设备故障数量 starLinkErrorTypes
export async function getStatLinkError() {
  return request(starLinkError, METHOD.GET)
}
//获取星链设备故障数量 starLinkErrorTypes
export async function getStatLinkErrorType(obj) {
  return request(starLinkErrorTypes, METHOD.GET, {
    start: obj.start,
    end:obj.end
  })
}
//获取星链设备故障数量 starLinkErrorTypes
export async function getStatLinkErrorNum(obj) {
  return request(starLinkErrorNum, METHOD.GET, {
    start: obj.start,
    end:obj.end
  })
}
//获取星链设备故障数量 starLinkErrorTypes
export async function getAlarmClass(obj) {
  return request(alarmClass, METHOD.GET, {
    start: obj.start,
    end:obj.end
  })
}


//获取星链主要状态
export async function getAllStar(obj) {
  return request(allStar, METHOD.GET, {
    page: obj.page,
    pagesize:obj.pagesize,
  })
}


export async function getLineAlarm(obj) {
  return request(lineAlarm, METHOD.GET, {
    starlinkId: obj.starlinkId,
    start: obj.start,
    end:obj.end,
    page: obj.page,
    pagesize:obj.pagesize,
  })
}
export async function getDeviceAlarm(obj) {
  return request(deviceAlarm, METHOD.GET, {
    pagesize: obj.pagesize,
    start: obj.start,
    end:obj.end,
    page: obj.page,
    number:obj.number
  })
}



export async function getRoutesConfig() {
  return request(ROUTES, METHOD.GET)
}

/**
 * 退出登录
 */
export function logout() {
  localStorage.removeItem(process.env.VUE_APP_ROUTES_KEY)
  localStorage.removeItem(process.env.VUE_APP_PERMISSIONS_KEY)
  localStorage.removeItem(process.env.VUE_APP_ROLES_KEY)
  removeAuthorization()
}

// 获取web 用户信息
export async function getUserInfo(username) {
  return request(userInfo, METHOD.GET, {
    username: username,
  })
}

// 获取历史升级任务 upgradeTask
export async function getupgradeTask(obj) {
  return request(upgradeTask, METHOD.GET, {
    start: obj.start,
    end: obj.end,
    page: obj.page,
    pagesize:obj.pageSize
  })
}

// 设备升级状态查询 starlinkUpgradeStatus
export async function getStarlinkUpgradeStatus(obj) {
  return request(starlinkUpgradeStatus, METHOD.GET, {
    taskId: obj.taskId,
  })
}
// 获取设备列表
export async function getStarlinkList(starlinkId) {
  return request(starlinkList, METHOD.GET, {
    starlinkId:starlinkId
  })
}

// 设备历史数据
export async function getHistoryStatus(obj) {
  return request(historyStatus, METHOD.GET, {
    starlinkId: obj.starlinkId,
    start: obj.start,
    end: obj.end,
    page: obj.page,
    pagesize: obj.pagesize,
    moduleId:obj.moduleId
  })
}
// 日志下载
export async function getDownloadHistory(obj) {
  return request(downloadHistory, METHOD.GET, {
    starlinkId: obj.starlinkId,
    start: obj.start,
    end: obj.end,
  })
}

// 获取星链图像 starlinkScene
export async function getStarlinkScene(starlinkId) {
  return request(starlinkScene, METHOD.GET, {
    starlinkId:starlinkId
  })
}

// 星链设备详情
export async function getStarlinkAllStatus(starlinkId) {
  return request(starlinkAllStatus, METHOD.GET, {
    starlinkId:starlinkId
  })
}
// 安全主机 电源控制
export async function postLightControl(data) {
  return request(lightControl, METHOD.POST,data)
}
// 灯光控制
export async function postPowerControl(data) {
  return request(powerControl, METHOD.POST, data)
}

export default {
  login,
  logout,
  starLogin,
  getStatLinkError,
  getLineAlarm,
  getDeviceAlarm,
  getStatLinkErrorType,
  getStatLinkErrorNum,
  getRoutesConfig,
  getAllStar,
  getUserInfo,
  getupgradeTask,
  getStarlinkUpgradeStatus,
  getStarlinkList,
  getHistoryStatus,
  getAlarmClass,
  getDownloadHistory,
  postDeleteStarlink,
  postUpgradeDizuo,
  postAddLink,
  postAddLinks,
  postUpgradeSignal,
  postUpgradeAi,
  postUpgradeDasuanli,
  getStarlinkAllStatus,
  postLightControl,
  postPowerControl,
  getStarlinkScene
}
